import java.util.Arrays;
import java.util.Scanner;

/**
 * Created with Intellij IDEA.
 * Description:
 * User: Zguoxu
 * Date: 2025-03-07
 * Time: 17:35
 */
public class Test {

    public static boolean torF(int[] arr){
        for (int i = 0; i < arr.length - 2; i++) {
            int count = 0;
            if(arr[i] % 2 == 0){
                continue;
            }else{
                for (int j = i + 1; j < i + 3; j++) {
                    if(arr[j] % 2 != 0){
                        count++;
                    }
                }
                if(count == 2){
                    return true;
                }
            }
        }
        return false;
    }

    public static void main(String[] args) {
        /*请你判断数组中是否存在连续三个元素都是奇数的情况*/
        int[] array = new int[]{1, 2, 34, 3, 5, 6, 7, 0, 67, 4};
        if(torF(array)){
            System.out.println("存在");
        }else{
            System.out.println("不存在");
        }
    }

    public static int mainNum(int[] array){
        int i = 0;
        for (i = 0; i < array.length; i++) {
            int count = 0;
            for (int j = 0; j < array.length; j++) {
                if(array[i] == array[j]){
                    count++;
                }
            }
            if(count > (array.length / 2)){
                return array[i];
            }
        }
        return -1;
    }
    public static void main8(String[] args) {
        /*给定一个大小为 n 的数组，找到其中的多数元素。
        多数元素是指在数组中出现次数 大于 ⌊ n/2 ⌋ 的元素。
         */
        int[] array = new int[]{1, 3, 1, 2, 2, 2, 2};
        System.out.println(mainNum(array));
    }

    public static int single(int[] array){
        int ret = 0;
        for (int i = 0; i < array.length; i++) {
            ret ^= array[i];
        }
        return ret;
    }
    public static void main7(String[] args) {
        int[] array = new int[]{4, 1, 4, 1, 2};
        System.out.println(single(array));
    }

    public static int[] addA(int[] nums, int target){
        int[] ret = new int[2];
        for (int i = 0; i < nums.length - 1; i++) {
            for (int j = i + 1; j < nums.length; j++) {
                if(nums[i] + nums[j] == target){
                    ret[0] = i;
                    ret[1] = j;
                }
            }
        }
        return ret;
    }

    public static void main6(String[] args) {
        int[] array = new int[]{2, 7, 11, 15};
        Scanner sc = new Scanner(System.in);

        int target = sc.nextInt();
        int[] sumarr = addA(array, target);
        System.out.println(Arrays.toString(sumarr));
    }

    public static void bubblesort(int[] array){
        for (int i = 0; i < array.length - 1; i++) {
            boolean flag = false;
            for (int j = 0; j < array.length - 1 - i; j++) {
                if(array[j] > array[j + 1]){
                    int tmp = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = tmp;
                    flag = true;
                }
            }
            if(flag == false){
                break;
            }
        }
    }
    public static void main5(String[] args) {
        /*给定一个整型数组, 实现冒泡排序(升序排序)*/
        int[] array = new int[]{1, 3, 5, 7, 9, 2, 4, 6, 8, 10};
        bubblesort(array);
        System.out.println(Arrays.toString(array));
    }

    public static int[] adapt(int[] array){
        int[] tmparray = new int[array.length];
        int left = 0;
        int right = array.length - 1;
        for (int i = 0; i < array.length; i++) {
            if(array[i] % 2 == 0){
                tmparray[right] = array[i];
                right--;
            }else{
                tmparray[left] = array[i];
                left++;
            }
        }
        return tmparray;
    }
    public static void main4(String[] args) {
        int[] array = new int[]{1, 2, 3, 4, 5, 6};
        int[] newarray = adapt(array);
        System.out.println(Arrays.toString(newarray));
    }

    public static double avg(int[] array){
        int sum = 0;
        for (int x:array) {
            sum += x;
        }
        return((double)sum/array.length);
    }
    public static void main3(String[] args) {
/*实现一个方法 avg, 以数组为参数,
求数组中所有元素的平均值(注意方法的返回值类型).*/
        int[] array = new int[]{1, 3, 5, 7, 9, 2, 4, 6, 8, 10};
        double average = avg(array);
        System.out.println(average);
    }

    public static int[] transform(int[] array){
        for (int i = 0; i < array.length; i++) {
            array[i] *= 2;
        }
        return array;
    }
    public static void main2(String[] args) {
/*实现一个方法 transform, 以数组为参数, 循环将数组中的每个元素乘以 2 ,
并设置到对应的数组元素上.
例如 原数组为 {1, 2, 3}, 修改之后为 {2, 4, 6}*/
        int[] array = new int[]{1, 2, 3};
        int[] newarray = transform(array);
        System.out.println(Arrays.toString(newarray));
    }

    public static void main1(String[] args) {
        int[] array = {1, 3, 5, 7, 9, 2, 4, 6, 8, 10};
        for (int i = 0; i < array.length - 1; i++) {
            boolean flag = false;
            for (int j = 0; j < array.length - 1 - i; j++) {
                if(array[j] > array[j + 1]){
                    int tmp = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = tmp;
                    flag = true;
                }
            }
            if(flag == false)
                break;
        }
        System.out.println(Arrays.toString(array));
    }
}
